package com.tuo51.childcare.domain.dailytask;

import com.tuo51.childcare.domain.vo.DailyTaskTemplateMeta;
import com.tuo51.foudation.model.Domain;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * 每日观察记录
 */
@Entity
@Table(name = "user_daily_task_template")
@EqualsAndHashCode(callSuper = true)
@Data
@TypeDef(name = "json", typeClass = JsonStringType.class)
public class DailyTaskTemplate extends Domain {

    @Column(columnDefinition = "int default 0 COMMENT '序号'", nullable = false)
    private Integer dailyIndex = 0;

    @Column(columnDefinition = "varchar(32) COMMENT '能区id'")
    private String dimensionId;

    @Column(columnDefinition = "int default 0 COMMENT '月龄高'", nullable = false)
    private Integer monthMax = 0;

    @Column(columnDefinition = "int default 0 COMMENT '月龄低'", nullable = false)
    private Integer monthMin = 0;

    @Column(columnDefinition = "int default 0 COMMENT '日龄高'", nullable = false)
    private Integer dayMax = 0;

    @Column(columnDefinition = "int default 0 COMMENT '日龄低'", nullable = false)
    private Integer dayMin = 0;

    @Column(columnDefinition = "int default 0 COMMENT '发育商低'", nullable = false)
    private Integer dqMax = 0;

    @Column(columnDefinition = "int default 0 COMMENT '发育商高'", nullable = false)
    private Integer dqMin = 0;

    @Column(columnDefinition = "int default 0 COMMENT '性别， 0/1/2'", nullable = false)
    private Integer gender = 0;

    @Column(columnDefinition = "int default 0 COMMENT '父母， 0/1/2'", nullable = false)
    private Integer parent = 0;

    @Column(columnDefinition = "varchar(256) COMMENT '封面图片'")
    private String cover;

    @Column(columnDefinition = "varchar(64) COMMENT '标题'")
    private String title;

    @Column(columnDefinition = "varchar(256) COMMENT '描述'")
    private String description;

    @Column(columnDefinition = "varchar(256) COMMENT '训练频次'")
    private String rate;

    @Column(columnDefinition = "varchar(256) COMMENT '训练时长'")
    private String duration;

    @Column(columnDefinition = "varchar(256) COMMENT '训练周期'")
    private String period;

    @Type(type = "json")
    @Column(columnDefinition = "JSON COMMENT '配置元数据' ")
    private DailyTaskTemplateMeta planMeta;

    @Column(columnDefinition = " bit DEFAULT 0 COMMENT '必选' ")
    private Boolean required = false;

    @Column(columnDefinition = "varchar(1024) COMMENT '操作指导'")
    private String manual;

    @Column(columnDefinition = "int default 0 COMMENT '类型'", nullable = false)
    private Integer type = 0;

    @Column(columnDefinition = "varchar(1024) COMMENT '链接指导'")
    private String ref;


    public static DailyTaskTemplate of(int dailyIndex, String cover, String title, String description,
                                       String rate, String duration, String period,
                                       String manual,
                                       String ref){
        DailyTaskTemplate ret = new DailyTaskTemplate();

        ret.setDailyIndex(dailyIndex);
        ret.setCover(cover);
        ret.setTitle(title);
        ret.setDescription(description);
        ret.setRate(rate);
        ret.setDuration(duration);
        ret.setPeriod(period);
        ret.setManual(manual);
        ret.setRef(ref);

        return ret;
    }

}
